/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Bai2;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileFilter;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;

import javax.swing.JTextField;
import javax.swing.filechooser.FileView;

/**
 *
 * @author Thu
 */
public class JFCListener implements ActionListener{

    public void actionPerformed(ActionEvent e) {
        JButton Browse=(JButton)e.getSource();
        final JFileChooser jfc=new JFileChooser();
        jfc.addChoosableFileFilter(new MyFileFilter());
        jfc.addChoosableFileFilter(new MyFileFilter1());
        jfc.setFileView(new MyFileView());
        int kk= jfc.showOpenDialog(Browse);
                        if(kk==JFileChooser.APPROVE_OPTION)
                        {
                            
                            Component[] components=Browse.getParent().getComponents();
                            File MyFile=jfc.getSelectedFile();
                            for(int i=0;i<components.length;i++)
                         {


                             if("Directory".equals(components[i].getName()))
                                {
                                    ((JTextField)components[i]).setText(MyFile.getPath());
                                }
                          }

              



                      



}
    }
}
